package com.hsogoo.study.autoconfiguration;

import com.hsogoo.study.autoconfiguration.bean.Person;
import com.hsogoo.study.autoconfiguration.bean.Work;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

/**
 * @Author huangsaigang
 * Created @2019-09-29.
 */
@Configuration
@EnableAutoConfiguration
public class AutoConfigurationApplication {

    public static void main(String[] args) {

        //非web方式启动
        ConfigurableApplicationContext context = new SpringApplicationBuilder(AutoConfigurationApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);

        //通过@Configuration导入
        String myBean = context.getBean("myBean", String.class);
        System.out.println("================通过@Configuration导入===================================");
        System.out.println(myBean);
        Person person = context.getBean("person", Person.class);
        System.out.println("=================通过ImportBeanDefinitionRegistrar导入===================");
        System.out.println(person);
        Work work = context.getBean(Work.class);
        System.out.println("=================通过ImportSelector导入==================================");
        System.out.println(work);

        //关闭上下文
        context.close();

    }
}
